import os.path

import yaml

from api_qiyeweixin.untils.tool import join_path


class YamlUtil:

    @staticmethod
    def get_yaml(filename):
        path = join_path("config", filename)

        if not os.path.exists(path):
            YamlUtil.set_yaml(filename)

        with open(path, mode='r', encoding="utf-8") as file:
            data = yaml.safe_load(file)

            return data

    @staticmethod
    def set_yaml(filename, data=None):
        path = join_path("config", filename)

        with open(path, mode='w', encoding="utf-8") as file:
            yaml.safe_dump(data, file)

            return True


if __name__ == '__main__':
    print(YamlUtil.get_yaml("xxx.yml"))
